package javase.ch02.method;

/**
 * @Desc TODO
 * @Author chenmin
 * @Date 2025/10/30
 */
public class JoinDemo {

    public static void main(String[] args) {
        System.out.println("main 开始执行任务...");

        MyThread1 t1 = new MyThread1("T1");
        MyThread2 t2 = new MyThread2("T2" , t1);

        t1.start();
        t2.start();

        //main执行任务
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+" i = "+i);
        }

        //直到MyThread2线程任务执行结束，才会放行，当前线程继续执行任务
        try {
            t2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println("main 结束执行任务...");
    }

}
